// 799. [主元] 快速排序  https://oj.rnd.huawei.com/problems/799/details
//给定一个划分后的正整数序列，请问有多少个元素可能是划分过程中选取的主元？
//并按升序输出这些主元。
// 遍历每个下标的左边的最大值, 右边的最小值,就是他自己.
// 暴力超时
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

// typedef pair<int,int> MAX_MIN;   //   <left_max, right_min>

struct MaxMin {
  int leftMax;
  int rightMin;
};

class Solution {
 public:
  // 待实现函数，在此函数中填入答题代码;
  vector<int> QuickSort(const vector<int>& numbers) {
    vector<int> result;
    vector<MaxMin> vtMM(numbers.size());
    // 左边的最大值
    vtMM[0].leftMax = numbers[0];
    for (int i = 1; i < numbers.size(); i++) {
      vtMM[i].leftMax = max(vtMM[i - 1].leftMax, numbers[i]);
    }
    // 右边的最小值
    vtMM[numbers.size() - 1].rightMin = numbers[numbers.size() - 1];
    for (int i = numbers.size() - 2; i >= 0; i--) {
      vtMM[i].rightMin = min(vtMM[i + 1].rightMin, numbers[i]);
    }
    for (int i = 0; i < numbers.size(); i++) {
      if (vtMM[i].leftMax == numbers[i] && vtMM[i].rightMin == numbers[i]) {
        result.push_back(numbers[i]);
      }
    }
    return result;
  }
};

inline int ReadInt() {
  int number;
  cin >> number;
  return number;
}

template <typename T>
inline vector<T> ReadVector(int size) {
  vector<T> objects(size);
  for (int i = 0; i < size; ++i) {
    cin >> objects[i];
  }
  return objects;
}

template <typename T>
inline void WriteVector(const vector<T>& objects, char delimeter = ' ') {
  auto it = objects.begin();
  if (it == objects.end()) {
    return;
  }
  cout << *it;
  for (++it; it != objects.end(); ++it) {
    cout << delimeter << *it;
  }
}

int main() {
  int numbersNum = ReadInt();
  vector<int> numbers = ReadVector<int>(numbersNum);
  Solution solu;
  auto res = solu.QuickSort(numbers);
  cout << "[";
  WriteVector(res, ' ');
  cout << "]" << endl;
  return 0;
}
